<?php
// Setup session firsth
/**
 * Here a test for the administrative functionality of the messageboard
 *
 * @author GHoogendoorn
 */
include("../includes/defs/constants.php");
include DIR_LANGUAGE.'nl/general.php';
include DIR_LANGUAGE.'nl/'.FILE_MESSAGEBOARD;

include_once DIR_ADMIN_CLASS.FILE_MESSAGEBOARD;
include_once DIR_ADMIN_CLASS.FILE_MESSAGEBOARD_STATUS;
include_once DIR_ADMIN_CLASS.FILE_MESSAGEBOARD_TYPE;

/*
echo"<pre>";
var_dump($_POST);
echo"</pre>";
*/
/* Init DB */
$msg_brd = new MessageBoard();

if (isset($_POST) && isset($_POST['action'])){

    switch ($_POST['action']){

        case 'new_status':
            if (    isset($_POST['name'])      &&
                    isset($_POST['desc'])        &&
                    (!empty($_POST['name']))   &&
                    (!empty($_POST['desc']))){
                $message = new MessageboardStatus();
                $ret = $message->addStatus( $_POST['name'], $_POST['desc'] );
                if ($ret !== FALSE){
                    /* Saved so unset the form values */
                    unset($_POST['name']);
                    unset($_POST['desc']);
                }
                unset ($message);

            } else {
                header('location:'.$_SERVER['PHP_SELF']);
            }

            break;
        case 'new_type':
            if (    isset($_POST['name'])      &&
                    isset($_POST['desc'])        &&
                    (!empty($_POST['name']))   &&
                    (!empty($_POST['desc']))){
                $message = new MessageboardType();
                $ret = $message->addType( $_POST['name'], $_POST['desc'] );
                
                if ($ret !== FALSE){
                    /* Saved so unset the form values */
                    unset($_POST['name']);
                    unset($_POST['desc']);
                }
                unset ($message);

            } else {
                header('location:'.$_SERVER['PHP_SELF']);
            }
            break;

        default:
            header('location:'.$_SERVER['PHP_SELF']);
            break;
    }
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <title>Test Admin Messageboard</title>
    </head>
    <body>
<?php
$message_status = new MessageboardStatus();
$list = $message_status->getStatusList();

if ( !empty($list)){
    echo "Current Statuslist:\n<table>";
    foreach( $list as $idx =>$row){
        echo "<tr><td>{$row[FIELD_MSG_STATUS_NAME]}</td>".
            "<td>{$row[FIELD_MSG_STATUS_DESC]}</td>".
            "<td>". constant($row[FIELD_MSG_STATUS_DESC]) . "</td>".
            "</tr>\n";
    }
    echo "</table><p/>\n";
} 
?>
    <form action="<?echo $_SERVER['PHP_SELF']; ?>" method="POST">
    <table border="0" cellspacing="0" cellpadding="3">
    <tr><td>Type:</td><td><input type="text" name="name" maxlength="32" value="<?php echo (isset($_POST['status']))? $_POST['status'] : ''; ?>" /></td><td></td></tr>
    <tr><td>Beschrijving:</td><td><input type="text" name="desc" maxlength="128" value="<?php echo (isset($_POST['desc']))? $_POST['desc'] : ''; ?>" /></td><td></td></tr>
    <tr><td colspan="2" align="left">
    <input type="hidden" name="action" value="new_status" />
    <input type="submit" value="proces" /></td></tr>
    </table>
    </form>
    <p><hr /></p>
<?php
$message_status = new MessageboardType();
$list = $message_status->getTypeList();

if ( !empty($list)){
    echo "Current Statuslist:\n<table>";
    foreach( $list as $idx =>$row){
        echo "<tr><td>". constant($row[FIELD_MSG_TYPE_NAME]) ."</td>".
            "<td>".$row[FIELD_MSG_TYPE_DESC]."</td>".
            "<td>".constant($row[FIELD_MSG_TYPE_DESC])."</tr>\n";
    }
    echo "</table><p/>\n";
}
?>
    <form action="<?echo $_SERVER['PHP_SELF']; ?>" method="POST">
    <table border="0" cellspacing="0" cellpadding="3">
    <tr><td>Status:</td><td><input type="text" name="name" maxlength="32" value="<?php echo (isset($_POST['name']))? $_POST['status'] : ''; ?>" /></td><td></td></tr>
    <tr><td>Beschrijving:</td><td><input type="text" name="desc" maxlength="128" value="<?php echo (isset($_POST['desc']))? $_POST['desc'] : ''; ?>" /></td><td></td></tr>
    <tr><td colspan="2" align="left">
    <input type="hidden" name="action" value="new_type" />
    <input type="submit" value="proces" /></td></tr>
    </table>
    </form>
    <p><hr /></p>
    </body>
</html>

